﻿using BCGPSMongoData;
using System;
using System.Collections.Generic;
using System.Text;
using AppSocketModel;
using BCGPSCommon;

namespace AppSocketService.DeviceRstTypeCntService
{
    /// <summary>
    /// 设备重启类型统计
    /// </summary>
    public class DeviceRstTypeCntService : IDeviceRstTypeCntService
    {
        private readonly MongoDBCommand<DeviceRstTypeCnt> mongoDBCommand = new MongoDBCommand<DeviceRstTypeCnt>("DeviceRstTypeCount");

        public DeviceRstTypeCntService()
        {
        }


        #region 获取全部
        public PageableList<DeviceRstTypeCnt> GetList(string imei, DateTime start, DateTime end, bool desc, int index, int size)
        {
            index = index > 0 ? index - 1 : 0;
            if (end.Hour == 0 && end.Minute == 0 && end.Second == 0)
                end = end.AddDays(1);
            start = MongoDBDateTime.GetUtc(start);
            end = MongoDBDateTime.GetUtc(end);
            if (string.IsNullOrWhiteSpace(imei))
                return mongoDBCommand.SelectDocumentsAsync(s => s.ReceiveDateTime >= start && s.ReceiveDateTime < end, s => s.DataPacketDateTime, desc, index * size, size).GetAwaiter().GetResult();
            else
            {
                return  mongoDBCommand.SelectDocumentsAsync(s => s.IMEI == imei && s.ReceiveDateTime >= start && s.ReceiveDateTime < end, s => s.DataPacketDateTime, desc, index * size, size).GetAwaiter().GetResult();

            }
        }
        #endregion
    }
}
